<?php

define('SERVER_TIMEZONE', 2);
define('DATE_TIME_FORMAT', 'd/m/Y H:i');
define('SIMPLE_DATE_TIME_FORMAT', 'd.m H:i');

function current_timezone() {
  return (int) $_SESSION['authUser']->timezone;
}

//returns a time difference in 'days hours:minutes:seconds" format
function timeDiffToTimeFormat($timestamp) {
  $res = ':'.($timestamp % 60);
  $t = floor($timestamp / 60);
  $res = ':'.($t % 60).$res;
  $t = floor($t / 60);
  $res = ($t % 24).$res;
  $t = floor($t / 24);
  if ($t > 0) $res = $t.LANG_days.$res;
  return $res;
}

//returns the GMT time from a timezone timestamp
function timeGmtFromTimezone($timestamp, $timezone) {
  return (int) ($timestamp - $timezone * 3600);
}

//returns the time for a specified timezone from a GMT timestamp
function timeTimezoneFromGmt($timestamp, $timezone) {
  return (int) ($timestamp + $timezone * 3600);
}

//returns the GMT current server time
function timeServerGmt() {
  return timeGmtFromTimezone(time(), SERVER_TIMEZONE);
}

//returns the current time for the specified timezone 
function timeTimezone($timezone) {
  return timeTimezoneFromGmt(timeServerGmt(), $timezone);
}

//returns the time left to a GMT timestamp
function timeLeftTo($timestamp) {
  return (int) ($timestamp - timeServerGmt());
}

function timeOutput($timestamp) {
  return date(DATE_TIME_FORMAT, timeTimezoneFromGmt($timestamp, current_timezone()));
}

function timeOutputSimple($timestamp) {
  return date(SIMPLE_DATE_TIME_FORMAT, timeTimezoneFromGmt($timestamp, current_timezone()));
}

?>